package com.dd.cloud.common.config.servlet;

import com.dd.cloud.common.interceptor.UserInterceptor;

import com.dd.cloud.common.utils.LocalDateConverter;
import com.dd.cloud.common.utils.LocalDateTimeConverter;
import com.dd.cloud.common.utils.LocalTimeConverter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器
 *
 * @author zk
 */
@Configuration
//@EnableConfigurationProperties(JwtProperties.class)
@Slf4j
public class MvcConfig implements WebMvcConfigurer {

    public static final String DEFAULT_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
    public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd";
    public static final String DEFAULT_TIME_PATTERN = "HH:mm:ss";
//    @Autowired
//    private JwtProperties prop;
//    @Autowired
//    private JwtUtils jwtUtils;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInterceptor()).addPathPatterns("/**");
    }

    @Bean
    public MethodValidationPostProcessor methodValidationPostProcessor() {
        return new MethodValidationPostProcessor();
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new LocalDateConverter(DEFAULT_DATE_PATTERN));
        registry.addConverter(new LocalDateTimeConverter(DEFAULT_DATE_TIME_PATTERN));
        registry.addConverter(new LocalTimeConverter(DEFAULT_TIME_PATTERN));
    }




}
